Repository navigation
refactor(dash-tui): build the Esc menu from one list of items - #913
Conversation
The Esc menu's item list is stated in three places that nothing but convention keeps in step: the wrap bound the key handling uses, the height the draw guard reserves, and the labels the draw routine paints. Pin what the menu does today before those are collapsed into one list: - the three rows drawn, in order, with the cursor only on the selected row, their column and their focus styling; - the smallest screen on which the menu is drawn at all (every item has to fit); - that the number of drawn rows equals the wrap bound; - that selection wraps in both directions over three rows and that each row runs its own action. No production code changes. Signed-off-by: Jussi Elo <jussi.elo@amd.com>
The Esc menu's item count was stated three times: `MENU_ITEMS` (the wrap bound of the key handling), `MENU_ITEM_COUNT` (the height the draw guard reserves) and the local label array in `draw_menu`, and the activation match restated the order a fourth time as bare indexes. Nothing but a doc comment kept them in step. `MENU_ITEMS` is now the one list, a slice of a new `MenuItem` enum that carries each row's label. The wrap bound is its length, `MENU_ITEM_COUNT` is derived from it, `draw_menu` iterates it, and the activation match is over `MenuItem`, so the compiler requires an arm for every row. No behaviour change: same three rows in the same order with the same labels, same wrap, same drawn output, and a selection past the last row still quits as the old `_` arm did (now pinned by a test). Signed-off-by: Jussi Elo <jussi.elo@amd.com>
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the refactor consolidating the dashboard’s Esc menu around a shared typed list.
No open issues 🎉
What changed in this PR
Consolidates the dashboard’s Esc menu around one typed MENU_ITEMS list, keeping rendering, navigation, sizing, and activation aligned without changing user-visible behavior.
Changes:
- Introduces
MenuItemwith shared labels and replaces duplicated counts and index-based activation. - Adds six regression tests covering menu appearance, sizing, navigation, activation, and the existing out-of-range fallback.
- Updates architecture documentation and an e2e step’s doc comment to describe the shared list.
| File | Description |
|---|---|
tests/e2e-cucumber/tests/e2e/dash_steps.rs |
Updates a doc comment only; step behavior is unchanged. |
docs/architecture.md |
Documents the shared menu definition and its consumers. |
crates/rocm-dash-tui/src/ui/menu.rs |
Derives rows and height from the list; adds rendering tests. |
crates/rocm-dash-tui/src/app/types.rs |
Defines MenuItem, its labels, and the ordered menu list. |
crates/rocm-dash-tui/src/app/mod.rs |
Re-exports MenuItem alongside MENU_ITEMS. |
crates/rocm-dash-tui/src/app/actions.rs |
Uses the list for navigation and activation; adds behavior tests. |
Review effort: Balanced
juhovainio
left a comment
There was a problem hiding this comment.
Looks good. The refactor is behaviour-neutral, and the wrap bound, popup height, drawn rows and activation all now derive from the single MENU_ITEMS list. The architecture doc is updated, and the existing dash-14/dash-34 scenarios are cited as the covering behaviour.
None of the inline notes below block the merge:
- an out-of-range selection currently maps to Quit;
- the new tests hardcode popup geometry and render twice;
- one test compares labels against the same
label()source, so it can't fail on a wrong label.
Could you confirm you broke the list (e.g. dropped a row from MENU_ITEMS) and saw the new tests go red? The PR body doesn't say. This is a diff-only read. CI should be green before merge: the Strix Halo nightly/release E2E lane was failing when I looked, and MI300X/W7900 were still pending.
| // A selection past the list (never set by `OpenMenu` or | ||
| // `MenuMove`, which keep it in range) still quits, as it did | ||
| // when this arm was the index fallback. | ||
| Some(MenuItem::Quit) | None => return request_quit(state), |
There was a problem hiding this comment.
An out-of-range menu_sel falls into the destructive Quit arm. Preserving the old _ behaviour is fine, but since the state is unreachable by construction, a debug_assert! or a no-op for None would be safer.
There was a problem hiding this comment.
Done in c509cea: the None arm no longer quits; an out-of-range menu_sel is now a no-op that leaves the menu open, with a short comment. It is a deliberate tightening of a state that is unreachable by construction (the commit message says so), and the test is now esc_menu_selection_past_the_last_row_does_nothing, which also asserts the menu stays open. Putting the Quit arm back turns it red.
| let theme = Theme::from_name("default-dark"); | ||
| let area = Rect::new(0, 0, 120, 30); | ||
| let mut term = Terminal::new(TestBackend::new(120, 30)).unwrap(); | ||
| term.draw(|f| super::draw_menu(f, area, 1, &theme)).unwrap(); |
There was a problem hiding this comment.
draw_menu is rendered twice in this test (term.draw and then rows). Rendering once and deriving the row text from the same buffer would be simpler.
There was a problem hiding this comment.
The test now renders once and builds the row text from that same buffer (6e52003).
| }; | ||
| // The box is 60 wide on a 120-column screen, so its left border is at | ||
| // x=30; the cursor column is 7 cells right of it and the label 2 more. | ||
| let (cursor_x, label_x) = (37u16, 39u16); |
There was a problem hiding this comment.
Hardcoded x=37/39 bakes in the popup width (60 on 120 cols), so an unrelated popup sizing change would break this. Deriving it from centered_rect or the frame's left border would be sturdier.
There was a problem hiding this comment.
The hardcoded x values are gone: the test finds the box's left border on the Help row and takes the cursor and label columns relative to it (6e52003). Changing the popup width from 60 to 44 leaves all nine menu tests green, while shifting the item column still turns the fixed-column test red.
| .iter() | ||
| .map(|(_, t)| t.trim_start_matches("▸ ")) | ||
| .collect(); | ||
| let listed: Vec<&str> = MENU_ITEMS.iter().map(|i| i.label()).collect(); |
There was a problem hiding this comment.
Both sides go through label(), so a wrong label can't fail this test; it only proves row count and order. Fine as is, as long as the other tests cover the wording.
There was a problem hiding this comment.
Added a literal Options, Help, Quit assertion next to the one that compares against label() (1be71db); changing the Help label to "Halp" fails the new assertion while the old label() comparison still passes.
An out-of-range `menu_sel` used to share the Quit arm of the Esc menu's activation match, so it would request a quit. Nothing can set it out of range (`OpenMenu` resets it and `MenuMove` wraps it), so no user-visible behaviour changes. This deliberately tightens that unreachable state: the lookup miss now does nothing and leaves the menu open instead of taking the destructive path. The test is renamed to match and also asserts the menu stays open. Signed-off-by: Jussi Elo <jussi.elo@amd.com>
…he border The fixed-column test rendered draw_menu twice, once for the buffer and once for the row text, and hardcoded the cursor and label columns as absolute x=37/39, which baked in the popup's width. It now renders once, builds the row text from that same buffer, and finds the box's left border on the Help row so the columns are taken relative to it. Changing the popup's width no longer breaks the test; shifting the item column inside the box still does. Signed-off-by: Jussi Elo <jussi.elo@amd.com>
esc_menu_draws_the_rows_of_the_list_the_selection_walks compares the drawn rows with MenuItem::label(), so a wrong label appeared on both sides and could not fail it. Add a literal Options, Help, Quit assertion alongside. Signed-off-by: Jussi Elo <jussi.elo@amd.com>
|
Thanks for the approval. Pushed c509cea, 6e52003 and 1be71db for your four inline notes (see the replies on each). On your question whether I broke the list and saw the tests go red: yes, and the PR body's "Mutation proof" section lists it. Against the first commit, adding a fourth label to the draw array only, setting |
Summary
The dashboard's Esc menu had its item count written down in three separate places, kept in step only by convention:
MENU_ITEMSinapp/types.rs(the wrap bound of the up/down keys),MENU_ITEM_COUNTinui/menu.rs(how tall the box must be before the menu is drawn at all), and a local["Options", "Help", "Quit"]array insidedraw_menu(the rows actually painted). The activation match inapp/actions.rsrestated the order a fourth time as bare indexes (0,1, anything else). Adding or removing a row meant editing all of them, and a missed copy would have shown as a row that can be selected but is not drawn, a row that is drawn but cannot be reached, or a row clipped off the bottom of a short box, with no compile error and no failing test.This change makes
MENU_ITEMSthe one list. It is now a slice of a newMenuItemenum (Options,Help,Quit) that carries each row's label. The wrap bound isMENU_ITEMS.len(),MENU_ITEM_COUNTis computed from it,draw_menuiterates it and printsitem.label(), and the activation match is overMenuItem, so the compiler now requires an arm for every row. This is part of the Phase 8.4-H follow-up work (behaviour-neutral consolidations); it is one bullet of that item and does not close it.Which copy wins and why
There was nothing to arbitrate: the three copies agreed (three rows: Options, Help, Quit), so the surviving behaviour is simply the current one. The list lives in
app/types.rsrather than inui/menu.rsbecause that file already owns the command-palette and options-tab lists (PALETTE_DESTS,OPTIONS_TABS) that the key handling and the renderer both read, anddocs/architecture.mdalready saysui/menu.rsdepends onapp/types.rsand not the reverse. Keeping the data there adds no module cycle. The existing shape (a const next to its siblings, read by both sides) is kept rather than introducing a new mechanism.What changed
app/types.rs:MENU_ITEMS: usize = 3becomesMENU_ITEMS: &[MenuItem], with the newMenuItemenum andMenuItem::label.app/mod.rs: re-exportsMenuItembesideMENU_ITEMS.app/actions.rs:MenuMovewraps overMENU_ITEMS.len();MenuActivatematchesMENU_ITEMS.get(menu_sel)onSome(MenuItem::Options),Some(MenuItem::Help)andSome(MenuItem::Quit) | None. TheNonecase keeps the old_arm's behaviour for a selection past the last row (it still quits). Nothing setsmenu_selout of range today (OpenMenuresets it andMenuMovewraps it), so this only preserves the old fallback exactly.ui/menu.rs:MENU_ITEM_COUNTisMENU_ITEMS.len() as u16;draw_menuloops overMENU_ITEMS; the local label array is gone.docs/architecture.md: theapp/types.rsentry said the Esc menu's own item count was a separate constant inui/menu.rs; it now says the rows, labels, wrap bound and reserved height all come from the one list.tests/e2e-cucumber/tests/e2e/dash_steps.rs: a doc comment on a step definition named the label array inui/menu.rs; it now points atMENU_ITEMS. Comment only, no scenario or step logic touched.The leaf-name test list against
origin/maindiffers only by the six added tests below.Verification
Commit order is characterisation first, then the consolidation. The first commit adds tests only and they pass on the unchanged code:
esc_menu_draws_options_help_quit_in_order_with_only_the_selected_row_marked: for each selection, the exact three rows below the logo, in order, with▸only on the selected row, on consecutive screen rows.esc_menu_item_rows_sit_at_a_fixed_column_with_focus_styling: the exact cells (cursor column, label column, accent colour and bold on the selected label, plain foreground and not bold on the others).esc_menu_is_drawn_only_when_the_box_is_tall_enough_for_every_item: on a 120-column screen, height 19 draws an empty frame (no logo, no items) and height 20 draws the logo and all three labels.esc_menu_selection_wraps_over_its_three_rows_and_each_row_runs_its_own_action: opens on row 0, up wraps to row 2, down wraps to row 0, a full lap visits 1, 2, 0; row 0 opens Options on tab 0, row 1 opens the global help, row 2 quits.esc_menu_draws_the_rows_of_the_list_the_selection_walks: the drawn rows equalMENU_ITEMSlabel for label (in the first commit this compared the number of drawn rows with the wrap bound).esc_menu_selection_past_the_last_row_still_quits. It passes on the old code too, by reading the old_arm; I did not run it against the old code.Mutation proof. Against the first commit (the three copies still separate), each divergence turns tests red:
draw_menu's array only: the ordered-rows test, the drawn-rows-equal-the-wrap-bound test and the height test fail;MENU_ITEMSto 4 only: the wrap test and the drawn-rows-equal-the-wrap-bound test fail;MENU_ITEM_COUNTto 4 only: the height test and the existingesc_menu_requires_room_for_all_itemsfail.Against the final code: dropping Help from
MENU_ITEMSfails six tests (the pins, the height tests andmenu_navigation_and_activation); adding a duplicate fourth entry fails the ordered-rows pin, both height tests and the wrap test whileesc_menu_draws_the_rows_of_the_list_the_selection_walksstays green, which is the point of the change (the drawn rows and the key handling can no longer disagree, so only the deliberate literal pins report that the menu changed); replacing theNonearm with a no-op failsesc_menu_selection_past_the_last_row_still_quits. Every mutation was restored with a targeted reverse edit.Ran:
cargo fmt --all --check;cargo clippy -p rocm-dash-tui --all-targets -- -D warnings;cargo test -p rocm-dash-tui --no-fail-fast(1002 unit tests plus the crate's integration tests, all passing);cargo xtask manifest --check;cargo xtask check-crate-edges;cargo xtask lycheeand the lychee commit hook; the leaf-name test-list diff against a cleanorigin/mainworktree; the leak scan overgit diff origin/main...HEAD.Not run: the Windows-target clippy cross-check (the toolchain cannot build
aws-lc-sysforx86_64-pc-windows-msvchere; none of the touched code is platform-gated);cargo xtask e2e,scripts/smoke_local.pyand the full workspace gate, which CI carries.User-visible behaviour
None. Same items, same order, same labels, same keys and the same drawn screen. No scenario is added because nothing a user can observe changes. The scenarios that already cover the menu and keep covering it are
@id:dash-chat-idle-escape-opens-menu(dash-14: Escape opens the menu from the Chat tab and a second Escape closes it) and@id:dash-esc-menu-quit-row-confirms-when-serving(dash-34: navigating to the Quit row and activating it asks the quit confirmation). Both are tagged only@requires-os:linux, so no GPU or nightly gate applies; they run on the Linux e2e lane in CI. I did not run them locally.Notes for reviewers
Read the two commits in order: the first only adds tests (green on the unchanged code), the second changes the production code and nothing in the tests except the one comparison that moved from a count to labels. The new
MenuItemenum does not make a variant missing fromMENU_ITEMSa compile error (stable Rust cannot check that without a derive macro the crate does not depend on); the doc comment onMENU_ITEMSsays so, asScrollTarget::ALLdoes for its list. The only other restatement of the order is theMenuActivatematch, which the compiler now checks for completeness.Open PRs: I checked the open list for PRs touching the menu code and found none that edit
ui/menu.rs,MENU_ITEMSor the activation arm. Several open PRs touchdocs/architecture.md, and #721 includes theui/menu.rsbullet as unchanged context, so a rebase may need a manual look at that file but the lines I changed (theapp/types.rsbullet) are not edited there. #868 editstests/e2e-cucumber/tests/e2e/dash_steps.rsin other step definitions, away from the doc comment changed here.